package com.ctsi.security.app.permissiontree;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class PermisionTypeNode implements Serializable,Cloneable {
    private static final long serialVersionUID = 4725391859675858969L;

    String id;
    String name;
    String inExtends;
    String lastId;
    Path path = new Path();
    Beans beans = new Beans();

    @Override
    public Object clone() throws CloneNotSupportedException {
        PermisionTypeNode newPer = (PermisionTypeNode) super.clone();
        if (path != null){
            newPer.setPath((Path) path.clone());
        }
        if (beans != null){
            newPer.setBeans((Beans) beans.clone());
        }
        return newPer;
    }

    public List<String> getPaths(){
        List<String> list = new ArrayList<String>();
        if(path == null){
            return list;
        }
        for(Item item:path.getItem()){
            list.add(item.getId());
        }
        return list;
    }

    public List<String> getIdBeans(){
        List<String> list = new ArrayList<String>();
        if(beans == null){
            return list;
        }
        for(Item item:beans.getItem()){
            list.add(item.getTextContent());
        }
        return list;
    }


    public String getPathStr(){
        StringBuilder sb = new StringBuilder();
        if(path == null){
            return sb.toString();
        }
        int i = 0;
        for(Item item:path.getItem()){
            if(i++!=0){
                sb.append('/');
            }
            sb.append(item.getId());
        }
        return sb.toString();
    }

    public String getPathNameStr(){
        StringBuilder sb = new StringBuilder();
        if(path == null){
            return sb.toString();
        }
        int i = 0;
        for(Item item:path.getItem()){
            if(i++!=0){
                sb.append('/');
            }
            sb.append(item.getTextContent());
        }
        return sb.toString();
    }

    public void addPath(String str,String name){
        if(path == null){
            path = new Path();
        }
        path.addItem(str,name);
    }
    public void addBean(String str){
        if(beans == null){
            beans = new Beans();
        }
        beans.addItem(str);
    }
    public PermisionTypeNode() {
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getInExtends() {
        return inExtends;
    }

    public void setInExtends(String inExtends) {
        this.inExtends = inExtends;
    }

    public String getLastId() {
        return lastId;
    }

    public void setLastId(String lastId) {
        this.lastId = lastId;
    }

    public Path getPath() {
        return path;
    }

    public void setPath(Path path) {
        this.path = path;
    }

    public Beans getBeans() {
        return beans;
    }

    public void setBeans(Beans beans) {
        this.beans = beans;
    }
}
